/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

/**
 *
 * @author olawale
 */
@Entity
@Table(name = "matches")
@NamedQueries({@NamedQuery(name = "Match.findAll", query = "SELECT m FROM Match m")})
public class Match implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "Id")
    private Integer id;
    @Column(name = "MatchDate")
    @Temporal(TemporalType.DATE)
    private Date matchDate;
    @Column(name = "Fixture")
    private Integer fixture;
    @Column(name = "HomeScore")
    private Integer homeScore;
    @Column(name = "AwayScore")
    private Integer awayScore;
    @Column(name = "Prediction")
    private Integer prediction;
    @JoinColumn(name = "Home", referencedColumnName = "Id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Team home;
    @JoinColumn(name = "Away", referencedColumnName = "Id")
    @ManyToOne(optional = false, fetch = FetchType.EAGER)
    private Team away;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "match", fetch = FetchType.EAGER)
    private List<Score> scoresCollection;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "match", fetch = FetchType.EAGER)
    private List<Prediction> predictionCollection;

    public Match() {
    }

    public Match(Integer id) {
        this.id = id;
    }

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public Date getMatchDate() {
        return matchDate;
    }

    public void setMatchDate(Date matchDate) {
        this.matchDate = matchDate;
    }

    public Integer getFixture() {
        return fixture;
    }

    public void setFixture(Integer fixture) {
        this.fixture = fixture;
    }

    public Integer getHomeScore() {
        return homeScore;
    }

    public void setHomeScore(Integer homeScore) {
        this.homeScore = homeScore;
    }

    public Integer getAwayScore() {
        return awayScore;
    }

    public void setAwayScore(Integer awayScore) {
        this.awayScore = awayScore;
    }

    public Integer getPrediction() {
        return prediction;
    }

    public void setPrediction(Integer prediction) {
        this.prediction = prediction;
    }

    public Team getHome() {
        return home;
    }

    public void setHome(Team home) {
        this.home = home;
    }

    public Team getAway() {
        return away;
    }

    public void setAway(Team away) {
        this.away = away;
    }

    public List<Score> getScoresCollection() {
        return scoresCollection;
    }

    public void setScoresCollection(List<Score> scoresCollection) {
        this.scoresCollection = scoresCollection;
    }

    public List<Prediction> getPredictionCollection() {
        return predictionCollection;
    }

    public void setPredictionCollection(List<Prediction> predictionCollection) {
        this.predictionCollection = predictionCollection;
    }

    public String getScores(){
        return homeScore + " - " + awayScore;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Match)) {
            return false;
        }
        Match other = (Match) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return home.getName() + " vs " + away.getName();
    }

}
